angular.module('myApp',['ngRoute','ngSanitize'])

//    该节示例可以查看https://www.w3cschool.cn/angularjs/angularjs-routing.html
//    w3cschool的AngularJS路由的教程
//    angularjs中文网的教程有错误，不能跑起来

//路由配置
.config(['$routeProvider',
    function ($routeProvider) {

        //$routeProvider提供路由service
        $routeProvider
            .when('/',{
                template:'this is index'
            })
            .when('/Book/:bookId', {
                templateUrl: 'book.html',
                controller: 'BookCtrl',
                controllerAs: 'book'
            })
            .when('/Book/:bookId/ch/:chapterId', {
                templateUrl: 'chapter.html',
                controller: 'ChapterCtrl',
                controllerAs: 'chapter'
            })
            .otherwise({
                redirectTo:'/'
            });
    }

])


.controller('navController',['$route', '$routeParams', '$location',
    function($route, $routeParams, $location) {
        this.$route = $route;
        this.$location = $location;
        this.$routeParams = $routeParams;
    }
])

    .controller('ExampleController', ['$scope', function($scope) {
        $scope.snippet =
            'Pretty text with some links:\n' +
            'http://angularjs.org/,\n' +
            'mailto:us@somewhere.org,\n' +
            'another@somewhere.org,\n' +
            'and one more: ftp://127.0.0.1/.';
        $scope.snippetWithSingleURL = 'http://angularjs.org/';
    }])

// Given:
// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
// Route: /Chapter/:chapterId/Section/:sectionId
//
// Then
//$routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'}

    .controller('BookCtrl', ['$routeParams', function($routeParams) {
        this.name = 'BookCtrl';
        this.params = $routeParams;
        console.log(this.params)
    }])

    .controller('ChapterCtrl', ['$routeParams', function($routeParams) {
        this.name = 'ChapterCtrl';
        this.params = $routeParams;
        console.log(this.params)
    }]);





